<template>
  <div>
      用户名:<input type="text" v-model="username">
      密码:<input type="text" v-model="password">
      <input type="button" value="登录" @click="login">
  </div>
</template>

<script>
export default {
    data(){
        return {
            username:"",
            password:"",
        }
    },
    methods:{
        login(){
            this.axios.post("/login",{"username":this.username,"password":this.password}).then(resp=>{
                console.log(resp.data)
                if(resp.data.level==1){
                    alert("学生登录成功")

                    sessionStorage.setItem("username",this.username)
                    sessionStorage.setItem("uid",resp.data.uid)
                    sessionStorage.setItem("score",resp.data.score)

                    this.$router.push({"path":"/course"})

                }else{
                    alert("老师登录成功")
                    this.$router.push({"path":"/student"})
                }
            })
        }
    }
}
</script>

<style>

</style>